﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Vending_machine_system.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class FileUploadController : ControllerBase
    {
        [HttpPost]
        public async Task<IActionResult> UploadFile(IFormFile file)
        {
          
            if (file ==null || file.Length == 0)
                return BadRequest("No file uploaded.");
            string ImgAdress = "C:\\Users\\刘琢\\Desktop\\文件夹\\项目\\Vending-machine-system\\Vending-machine-system\\wwwroot\\Img\\";
            var savePath = Path.Combine(Directory.GetCurrentDirectory(),ImgAdress, file.FileName);

            using (var stream = new FileStream(savePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
            return Ok(new { fileName=file.FileName });
        }
    }
}
